﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using LiveChartsCore;
using LiveChartsCore.Drawing;
using LiveChartsCore.Measure;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using MsBox.Avalonia.Enums;
using Nlnet.Avalonia.Controls;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using 畜牧业审核程序国产.Models;
using 畜牧业审核程序国产.Models.ToolsClass;


using Icon = MsBox.Avalonia.Enums.Icon;
using 畜牧业审核程序国产.Models.DataGridMsgs;
using 畜牧业审核程序国产.Models.SimpleFactory;

namespace 畜牧业审核程序国产.ViewModels
{
    internal class Page3ViewModel : MyViewModelBase
    {
        #region 声明要用到的字段
        DataTable dtOfSingleIndicator = new DataTable();
        private readonly string withYSTableNameNow = Global.PlatformNow + Global.StrYearNow + Global.StrSeasonNow + "A209";
        private readonly string withYSTableNamePre = Global.PlatformPre + Global.StrYearPre + Global.StrSeasonPre + "A209";
        private  string withYSTableNameSpring
        {
            get 
            {
                if (Global.IntYearNow>2025)
                {
                    return "统计云" + Global.StrYearNow + "第一季度A209";
                }
                else
                {
                    return "一套表" + Global.StrYearNow + "第一季度A209";
                }
            }
        }
        private string withYSTableNameSummer
        {
            get
            {
                if (Global.IntYearNow > 2025)
                {
                    return "统计云" + Global.StrYearNow + "第二季度A209";
                }
                else
                {
                    return "一套表" + Global.StrYearNow + "第二季度A209";
                }
            }
        }
        
        private readonly string withYSTableNameYOY = Global.PlatformYOY + Global.StrYearYOY + Global.StrSeasonYOY + "A209";
        private readonly string[] arrStrIndicatorsBeShowd = new string[] {"期末存栏合计01","25公斤以下仔猪存栏数02"
                                ,"待育肥猪存栏数03","50公斤以上待育肥猪存栏数04","种猪存栏数05","能繁殖母猪存栏数06","当季增加头数07","自繁头数08","购进头数09","当季减少头数10",
                                "自宰肥猪头数11" ,"出售肥猪头数（不包括出售待育肥猪）12","出售肥猪金额（元）13","出售肥猪重量（公斤）14","其它原因减少（包括死亡、疫病捕杀）15",
                                "出售25公斤以下仔猪头数16","出售25公斤以下仔猪金额（元）17","出售25公斤以下仔猪重量（公斤）18"};
        #endregion
        #region 声明用户选择了以后,SelectedItem或SelectedValue关联的单个值.selectedItem是键值对,而selectedValue是键值对的值,配合selectedValuePath使用
        private bool _isShowSubordinateEnable =true;

        public bool IsShowSubordinateEnable
        {
            get { return _isShowSubordinateEnable; }
            set { SetProperty(ref _isShowSubordinateEnable, value); }
        }


        private KeyValuePair<string, string> _selectedCity;

        public KeyValuePair<string, string> SelectedCity
        {
            get { return _selectedCity; }
            set
            {
                SetProperty(ref _selectedCity, value);
                //选择了市以后,把县展现出来
                if (value.Value != null)
                {
                    // Models.MyDBOperator ShowOperator = new Models.MyDBOperator();改用单例模式
                    Models.MyDBOperator ShowOperator = MyDBOperator.DBOperatorInstance;
                    if (value.Value.Equals("全部"))
                    {
                        CountryCln.Clear();
                        CountryCln.Add(new KeyValuePair<string, string>("0", "全部"));
                        SelectedCountry = new KeyValuePair<string, string>("change", "change");
                        SelectedCountry = new KeyValuePair<string, string>(CountryCln[0].Key, CountryCln[0].Value);

                    }
                    else if (value.Value.Contains("未导入"))
                    {
                        return;
                    }
                    else
                    {
                        string sqlToGetAllCountry = $"select 县代码,县 from {withYSTableNameNow} where 市代码 = '{value.Key}' group by 县代码,县";
                        DataTable dtOfCountry = ShowOperator.GetDataTable(sqlToGetAllCountry);
                        if (dtOfCountry.Rows.Count == 0 || dtOfCountry == null)
                        {
                            CountryCln.Clear();
                            CountryCln.Add(new KeyValuePair<string, string>("0", "未导入本季度A209表或者导入错误"));
                            SelectedCountry = new KeyValuePair<string, string>("change", "change");
                            SelectedCountry = new KeyValuePair<string, string>(CountryCln[0].Key, CountryCln[0].Value);
                            return;

                        }
                        CountryCln.Clear();
                        CountryCln.Add(new KeyValuePair<string, string>("0", "全部"));
                        //var keys = dtOfCountry.AsEnumerable()
                        //    .Select(row => row.Field<string>("县")).ToArray();
                        for (int i = 0; i < dtOfCountry.Rows.Count; i++)
                        {
                            DataRow row = dtOfCountry.Rows[i];
                            CountryCln.Add(new KeyValuePair<string, string>(row["县代码"].ToString(), row["县"].ToString()));
                        }
                        //                        具体来说，在以下情况下，属性的 setter 不会被触发：

                        //当新值和旧值相等时：如果 SetProperty(ref _selectedTown, value); 方法内部实现了某种形式的值比较（例如使用 Equals() 或者直接比较引用），并且发现新值和旧值是相同的，那么它可能选择不执行设置操作。这通常是为了避免不必要的通知事件或者当值没有实际变化时重新计算或更新UI。
                        //在某些框架或库中，SetProperty 方法可能会检查传入的新值是否与当前存储的私有字段不同，只有在不同的情况下才会继续进行设置操作并可能触发更改通知。如果两个 KeyValuePair<string, string> 对象具有相同的键和值，它们将被视为相等，即使它们是不同的实例。
                        SelectedCountry = new KeyValuePair<string, string>("change", "change");
                        SelectedCountry = new KeyValuePair<string, string>(CountryCln[0].Key, CountryCln[0].Value);
                    }
                }
                SetProperty(ref _selectedCity, value);
            }
        }
        private KeyValuePair<string, string> _selectedCountry;

        public KeyValuePair<string, string> SelectedCountry
        {
            get { return _selectedCountry; }
            set
            {
                SetProperty(ref _selectedCountry, value);

                if (Regex.IsMatch(value.Value, "全部"))
                {
                    TownCln.Clear();
                    TownCln.Add(new KeyValuePair<string, string>("0", "全部"));
                    SelectedTown = new KeyValuePair<string, string>("change", "change");//不加这个，就无法更新，SetProperty 方法可能会检查传入的新值是否与当前存储的私有字段不同，只有在不同的情况下才会继续进行设置操作并可能触发更改通知。如果两个 KeyValuePair<string, string> 对象具有相同的键和值，它们将被视为相等，即使它们是不同的实例。
                    SelectedTown = new KeyValuePair<string, string>(TownCln[0].Key, TownCln[0].Value);
                }
                else//如果县这里选择的不是全部,而是某个具体的县,那么要把所有乡镇和"全部"一起作为townCln的值
                {
                    // Models.MyDBOperator ShowOperator = new Models.MyDBOperator();改用单例模式
                    MyDBOperator ShowOperator = MyDBOperator.DBOperatorInstance;
                    string sql = $"select 乡镇代码,乡 from {withYSTableNameNow} WHERE 县代码 = '{SelectedCountry.Key}' group by 乡镇代码,乡";
                    DataTable dt = ShowOperator.GetDataTable(sql);
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        TownCln.Clear();
                        TownCln.Add(new KeyValuePair<string, string>("0", "未导入A209表或A209表导入错误"));
                        SelectedTown = new KeyValuePair<string, string>("change", "change");
                        SelectedTown = new KeyValuePair<string, string>(TownCln[0].Key, TownCln[0].Value);

                        return;
                    }
                    TownCln.Clear();
                    TownCln.Add(new KeyValuePair<string, string>("0", "全部"));
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dtRow = dt.Rows[i];
                        TownCln.Add(new KeyValuePair<string, string>(dtRow[0].ToString(), dtRow[1].ToString()));

                    }
                    // SelectedTown = TownCln[0];
                    SelectedTown = new KeyValuePair<string, string>("change", "change");
                    SelectedTown = new KeyValuePair<string, string>(TownCln[0].Key, TownCln[0].Value);
                }
                SetProperty(ref _selectedCountry, value);
            }
        }
        private KeyValuePair<string, string> _selectedTown;

        public KeyValuePair<string, string> SelectedTown
        {
            get { return _selectedTown; }
            set {
                if (value.Value.Equals("全部")==false)
                {
                    IsShowSubordinateEnable = false;
                }
                else
                {
                    IsShowSubordinateEnable = true;
                }
                SetProperty(ref _selectedTown, value); 
            }
        }
        private KeyValuePair<string, string> _selectedIndicator;

        public KeyValuePair<string, string> SelectedIndicator
        {
            get { return _selectedIndicator; }
            set { SetProperty(ref _selectedIndicator, value); }
        }
        #endregion
        #region 用户选择的期别

        private ObservableCollection<string> _period = new ObservableCollection<string>();
        public ObservableCollection<string> Period
        {
            get => _period;
            set
            {
                SetProperty(ref _period, value);
            }
        }
        private void SetPeroid()
        {
            if (Global.IntSeasonNow == 1)
            {
                this.Period.Add("本季度");
            }
            else
            {
                this.Period.Add("本季度");
                this.Period.Add("一到本季度");
            }
        }

        private string _selectedPeriod;
        public string SelectedPeriod
        {
            get { return _selectedPeriod; }
            set { SetProperty(ref _selectedPeriod, value); }
        }
        #endregion
        #region MassPigMsgs和SingleIndicatorPigMsgs
        private ObservableCollection<MassPigMsgs> _massPigCln = new ObservableCollection<MassPigMsgs>();

        public ObservableCollection<MassPigMsgs> MassPigCln
        {
            get { return _massPigCln; }
            set { SetProperty(ref _massPigCln, value); }
        }
        private ObservableCollection<SingleIndicatorMsg> _singleIndicatorPigCln = new ObservableCollection<SingleIndicatorMsg>();

        public ObservableCollection<SingleIndicatorMsg> SingleIndicatorPigCln
        {
            get { return _singleIndicatorPigCln; }
            set { _singleIndicatorPigCln = value; }
        }

        #endregion
        Animal 生猪规模户信息 = null;
        Models.ShowMsg showMsg;
        #region 构造函数
        public Page3ViewModel()
        {
            //要先进行县乡名称修正
            //需要用到的表:1到本季度的用表         本季度\上季度\同比季度


           
            showMsg = new Models.ShowMsg();
            //this.ShowAllMsgCommand = new RelayCommand(ShowAllMsgs);
             this.ShowAllMsgCommand = new RelayCommand(async ()=>await ShowPigMassMsgInDataGridAsync());
            // this.ShowSingleMsgCommand = new RelayCommand(() => ShowSingleMsgOnlyNow());
            this.ShowSingleMsgCommand = new RelayCommand(async () =>await ShowSingleIndicatorMsgInDataGridAsync());
            //this.ShowAllOwnerMsgCommand = new RelayCommand(() => ShowAllOwnerMsg());
            this.ShowAllOwnerMsgCommand = new RelayCommand(async () =>await ShowMsgByAllFarmersInDataGridAsync());
            //this.AllOutCommand = new RelayCommand(() => { AllOut(DTAll); });
            //this.SingleOutCommand = new RelayCommand(() => SingleOut(DTForSingleIndicator));
            SetPeroid();
            MySimpleFactory factory = new MySimpleFactory();
             生猪规模户信息 =   factory.CreateAnimal("生猪");

            try
            {
                MyDBOperator myDbOperator = MyDBOperator.DBOperatorInstance;
                
                if (myDbOperator.CheckIfTableExists(withYSTableNameNow)==false)
                {
                    CityCln.Clear();
                    CityCln.Add(new KeyValuePair<string, string>("0", $"未导入{withYSTableNameNow},或导入错误"));
                    return;
                }
                CityCln = showMsg.GetAllCityItems(withYSTableNameNow);
                IndicatorCln = showMsg.GetAllIndicators("猪", withYSTableNameNow);
            }
            catch (Exception ex)
            {
                StaticLogger.SystemError(ex.Message);
                throw;
            }
        }

       

        #endregion
        //string[] _arrStrIndicatorsOfPig = new string[] {"当季出栏数", "期末存栏合计01", "25公斤以下仔猪存栏数02",
        //    "待育肥猪存栏数03","50公斤以上待育肥猪存栏数04","种猪存栏数05","能繁殖母猪存栏数06","当季增加头数07","自繁头数08","购进头数09",
        //    "当季减少头数10","自宰肥猪头数11", "出售肥猪头数（不包括出售待育肥猪）12","出售肥猪金额（元）13",
        //    "出售肥猪重量（公斤）14","其它原因减少（包括死亡、疫病捕杀）15","出售25公斤以下仔猪头数16","出售25公斤以下仔猪金额（元）17",
        //    "出售25公斤以下仔猪重量（公斤）18"};
        private async Task ShowSingleIndicatorMsgInDataGridAsync()
        {
            string nameInDTOfSingleIndicator = null;
            string pieTitleName = null;
            if (SelectedCity.Value == null || SelectedCountry.Value == null || SelectedTown.Value == null)
            {
                await MyMessagebox.ShowAsyncInMainWindow("市、县、乡镇至少有一个下拉框未选择内容!", Icon.Error);
                return;
            }
            if (string.IsNullOrEmpty(SelectedIndicator.Value))
            {
                await MyMessagebox.ShowAsyncInMainWindow("未选择具体指标!", Icon.Error);
                return;
            }
            //先判断一下是否有表缺失
            string[] allNeedTables = new string[] { withYSTableNameNow, withYSTableNamePre,withYSTableNameYOY };
            var myDBOperator = MyDBOperator.DBOperatorInstance;
            var notExistTables = myDBOperator.CheckTablesExist(allNeedTables);
            string allNotExistTablesJoin = null;
            if (notExistTables.Count > 0)
            {
                for (int i = 0; i < notExistTables.Count; i++)
                {
                    //allNotExistTablesJoin += $"、{notExistTables[i].Substring(3)}";
                    allNotExistTablesJoin += $"、{notExistTables[i]}";
                }
                allNotExistTablesJoin = allNotExistTablesJoin.Substring(1);
                await MyMessagebox.ShowAsyncInMainWindow(allNotExistTablesJoin + "不存在,请先导入", Icon.Warning);
                return;
            }
            //没有缺失的话要先市县乡名称修正一下
            if (SelectedCity.Value.Equals("全部"))//全省的
            {
                dtOfSingleIndicator =
                    生猪规模户信息.GetDTSingleIndicatorOfSubordinateThisSeasonByCity(SelectedIndicator);
                SingleIndicatorPigCln.Clear();
                for (int i = 0; i < dtOfSingleIndicator.Rows.Count; i++)
                {
                    DataRow row = dtOfSingleIndicator.Rows[i];
                    // 使用 Convert.IsDBNull 检查并提供默认值
                    var 地区名称 = row.Field<string>(0) ?? "未知";
                    var 地区编码 = row.Field<string>(1) ?? "未知";

                    // 使用 Convert.ToDouble 并处理可能的 null 值
                    var 当季指标值 = Convert.ToDouble(row.IsNull(2) ? 0 : row[2]);
                    var 上季指标值 = Convert.ToDouble(row.IsNull(3) ? 0 : row[3]);
                    var 同比季度指标值 = Convert.ToDouble(row.IsNull(4) ? 0 : row[4]);
                    var 环比增量 = Convert.ToDouble(row.IsNull(5) ? 0 : row[5]);
                    var 同比增量 = Convert.ToDouble(row.IsNull(6) ? 0 : row[6]);
                    var 环比增幅 = Convert.ToDouble(row.IsNull(7) ? 0 : row[7]);
                    var 同比增幅 = Convert.ToDouble(row.IsNull(8) ? 0 : row[8]);
                    var 当季占比 = Convert.ToDouble(row.IsNull(9) ? 0 : row[9]);
                    var 上季占比 = Convert.ToDouble(row.IsNull(10) ? 0 : row[10]);
                    var 同比季度占比 = Convert.ToDouble(row.IsNull(11) ? 0 : row[11]);
                    SingleIndicatorPigCln.Add(new SingleIndicatorMsg(地区名称, 地区编码, 当季指标值, 上季指标值,
                        同比季度指标值, 环比增量, 同比增量, 环比增幅, 同比增幅, 当季占比, 上季占比, 同比季度占比));
                }
                nameInDTOfSingleIndicator = "市";
                pieTitleName = "分地市";
            }
            else if (SelectedCity.Value.Equals("全部") == false && SelectedCountry.Value.Equals("全部") == true)//某个市的
            {
                dtOfSingleIndicator = 
                生猪规模户信息.GetDTSingleIndicatorOfSubordinateThisSeasonByCountry(SelectedCity, SelectedIndicator);
                SingleIndicatorPigCln.Clear();
                for (int i = 0; i < dtOfSingleIndicator.Rows.Count; i++)
                {
                    DataRow row = dtOfSingleIndicator.Rows[i];
                    // 使用 Convert.IsDBNull 检查并提供默认值
                    var 地区名称 = row.Field<string>(0) ?? "未知";
                    var 地区编码 = row.Field<string>(1) ?? "未知";

                    // 使用 Convert.ToDouble 并处理可能的 null 值
                    var 当季指标值 = Convert.ToDouble(row.IsNull(2) ? 0 : row[2]);
                    var 上季指标值 = Convert.ToDouble(row.IsNull(3) ? 0 : row[3]);
                    var 同比季度指标值 = Convert.ToDouble(row.IsNull(4) ? 0 : row[4]);
                    var 环比增量 = Convert.ToDouble(row.IsNull(5) ? 0 : row[5]);
                    var 同比增量 = Convert.ToDouble(row.IsNull(6) ? 0 : row[6]);
                    var 环比增幅 = Convert.ToDouble(row.IsNull(7) ? 0 : row[7]);
                    var 同比增幅 = Convert.ToDouble(row.IsNull(8) ? 0 : row[8]);
                    var 当季占比 = Convert.ToDouble(row.IsNull(9) ? 0 : row[9]);
                    var 上季占比 = Convert.ToDouble(row.IsNull(10) ? 0 : row[10]);
                    var 同比季度占比 = Convert.ToDouble(row.IsNull(11) ? 0 : row[11]);
                    SingleIndicatorPigCln.Add(new SingleIndicatorMsg(地区名称, 地区编码, 当季指标值, 上季指标值,
                      同比季度指标值, 环比增量, 同比增量, 环比增幅, 同比增幅, 当季占比, 上季占比, 同比季度占比));
                }
                nameInDTOfSingleIndicator = "县";
                pieTitleName = "分县";
            }
            else if (SelectedCity.Value.Equals("全部") == false && SelectedCountry.Value.Equals("全部") == false && SelectedTown.Value.Equals("全部") == true)//某个县的
            {
                dtOfSingleIndicator =
                    生猪规模户信息.GetDTSingleIndicatorOfSubordinateThisSeasonByTown(SelectedCountry, SelectedIndicator);
                SingleIndicatorPigCln.Clear();
                for (int i = 0; i < dtOfSingleIndicator.Rows.Count; i++)
                {
                    DataRow row = dtOfSingleIndicator.Rows[i];
                    // 使用 Convert.IsDBNull 检查并提供默认值
                    var 地区名称 = row.Field<string>(0) ?? "未知";
                    var 地区编码 = row.Field<string>(1) ?? "未知";

                    // 使用 Convert.ToDouble 并处理可能的 null 值
                    var 当季指标值 = Convert.ToDouble(row.IsNull(2) ? 0 : row[2]);
                    var 上季指标值 = Convert.ToDouble(row.IsNull(3) ? 0 : row[3]);
                    var 同比季度指标值 = Convert.ToDouble(row.IsNull(4) ? 0 : row[4]);
                    var 环比增量 = Convert.ToDouble(row.IsNull(5) ? 0 : row[5]);
                    var 同比增量 = Convert.ToDouble(row.IsNull(6) ? 0 : row[6]);
                    var 环比增幅 = Convert.ToDouble(row.IsNull(7) ? 0 : row[7]);
                    var 同比增幅 = Convert.ToDouble(row.IsNull(8) ? 0 : row[8]);
                    var 当季占比 = Convert.ToDouble(row.IsNull(9) ? 0 : row[9]);
                    var 上季占比 = Convert.ToDouble(row.IsNull(10) ? 0 : row[10]);
                    var 同比季度占比 = Convert.ToDouble(row.IsNull(11) ? 0 : row[11]);
                    SingleIndicatorPigCln.Add(new SingleIndicatorMsg(地区名称, 地区编码, 当季指标值, 上季指标值,
                        同比季度指标值, 环比增量, 同比增量, 环比增幅, 同比增幅, 当季占比, 上季占比, 同比季度占比));
                }
                nameInDTOfSingleIndicator = "乡";
                pieTitleName = "分乡镇"; 
            }
            else if(SelectedCity.Value.Equals("全部") == false && SelectedCountry.Value.Equals("全部") == false && SelectedTown.Value.Equals("全部") == false)//某个乡镇的
            {
                dtOfSingleIndicator =
                       生猪规模户信息.GetDTSingleIndicatorOfSubordinateThisSeasonOfASelectedTown(SelectedTown, SelectedIndicator);
                SingleIndicatorPigCln.Clear();
                for (int i = 0; i < dtOfSingleIndicator.Rows.Count; i++)
                {
                    DataRow row = dtOfSingleIndicator.Rows[i];
                    // 使用 Convert.IsDBNull 检查并提供默认值
                    var 地区名称 = row.Field<string>(0) ?? "未知";
                    var 地区编码 = row.Field<string>(1) ?? "未知";

                    // 使用 Convert.ToDouble 并处理可能的 null 值
                    var 当季指标值 = Convert.ToDouble(row.IsNull(2) ? 0 : row[2]);
                    var 上季指标值 = Convert.ToDouble(row.IsNull(3) ? 0 : row[3]);
                    var 同比季度指标值 = Convert.ToDouble(row.IsNull(4) ? 0 : row[4]);
                    var 环比增量 = Convert.ToDouble(row.IsNull(5) ? 0 : row[5]);
                    var 同比增量 = Convert.ToDouble(row.IsNull(6) ? 0 : row[6]);
                    var 环比增幅 = Convert.ToDouble(row.IsNull(7) ? 0 : row[7]);
                    var 同比增幅 = Convert.ToDouble(row.IsNull(8) ? 0 : row[8]);
                    var 当季占比 = Convert.ToDouble(row.IsNull(9) ? 0 : row[9]);
                    var 上季占比 = Convert.ToDouble(row.IsNull(10) ? 0 : row[10]);
                    var 同比季度占比 = Convert.ToDouble(row.IsNull(11) ? 0 : row[11]);
                    SingleIndicatorPigCln.Add(new SingleIndicatorMsg(地区名称, 地区编码, 当季指标值, 上季指标值,
                        同比季度指标值, 环比增量, 同比增量, 环比增幅, 同比增幅, 当季占比, 上季占比, 同比季度占比));
                }
                nameInDTOfSingleIndicator = "户主姓名";
                pieTitleName = "分户";
            }
            if (dtOfSingleIndicator != null)
            {
                List<ISeries> circleConsistOfPiecesOfIndicatorSeasonNowConvertToArrayFinally = new List<ISeries>();
                List<ISeries> circleConsistOfPiecesOfIndicatorSeasonPreConvertToArrayFinally = new List<ISeries>();
                List<ISeries> circleConsistOfPiecesOfIndicatorSeasonYOYConvertToArrayFinally = new List<ISeries>();
                List<double> listColumnSeriesValuesIncreaseOfPreConvertToArrayLast =new List<double>();
                List<double> listColumnSeriesValuesIncreaseOfYOYConvertToArrayLast = new List<double>();
                List<double> listLineSeriesValuesIncreaseOfPreConvertToArrayLast = new List<double>();
                List<double> listLineSeriesValuesIncreaseOfYOYConvertToArrayLast = new List<double>();
                List<string> listColumnsXAxisNames = new List<string>();
                List<string> listLineXAxisNames = new List<string>();
                for (int i = 0; i < dtOfSingleIndicator.Rows.Count-1; i++)
                {
                    DataRow row = dtOfSingleIndicator.Rows[i];
                    AddOnePieSeriesToCircleList(row, nameInDTOfSingleIndicator, $"本季度{SelectedIndicator.Value}", ref circleConsistOfPiecesOfIndicatorSeasonNowConvertToArrayFinally);
                    AddOnePieSeriesToCircleList(row, nameInDTOfSingleIndicator, $"上季度{SelectedIndicator.Value}", ref circleConsistOfPiecesOfIndicatorSeasonPreConvertToArrayFinally);
                    AddOnePieSeriesToCircleList(row, nameInDTOfSingleIndicator, $"同比季度{SelectedIndicator.Value}", ref circleConsistOfPiecesOfIndicatorSeasonYOYConvertToArrayFinally);
                    AddTw0TotalColumsToCart(row, 0, "环比增量", "同比增量", ref listColumnSeriesValuesIncreaseOfPreConvertToArrayLast, ref listColumnSeriesValuesIncreaseOfYOYConvertToArrayLast, ref listColumnsXAxisNames);
                    AddTw0TotalColumsToCart(row, 0, "环比增幅(%)", "同比增幅(%)", ref listLineSeriesValuesIncreaseOfPreConvertToArrayLast, ref listLineSeriesValuesIncreaseOfYOYConvertToArrayLast, ref listLineXAxisNames);
                }
                if (circleConsistOfPiecesOfIndicatorSeasonNowConvertToArrayFinally.Count>0)
                {
                    PieSeriesOfNow = circleConsistOfPiecesOfIndicatorSeasonNowConvertToArrayFinally.ToArray();
                    TitleOfPieSeriesNow = SetTitleOfPie($"规模户{SelectedIndicator.Value}{pieTitleName}本期占比情况示意图");
                }
                else
                {
                    PieSeriesOfNow = null;
                    TitleOfPieSeriesNow = null;
                }
                if ( circleConsistOfPiecesOfIndicatorSeasonPreConvertToArrayFinally.Count > 0)//如果上季度的数据不为空,就显示到界面上
                {
                    PieSeriesOfPre = circleConsistOfPiecesOfIndicatorSeasonPreConvertToArrayFinally.ToArray();
                    //TitleOfPieSeriesPre = base.SetTitleOfPie("规模户上季度" + this.SelectedIndicator.Value + PieTitleName + "数据和比重示意图(%)");
                    TitleOfPieSeriesPre = base.SetTitleOfPie("规模户" + this.SelectedIndicator.Value +pieTitleName + "上期占比情况示意图");
                }
                else
                {
                    PieSeriesOfPre = null;
                    TitleOfPieSeriesPre = null;
                }
                if (circleConsistOfPiecesOfIndicatorSeasonYOYConvertToArrayFinally.Count > 0)//如果同比季度的数据不为空,就显示到界面上
                {
                    PieSeriesOfYOY = circleConsistOfPiecesOfIndicatorSeasonYOYConvertToArrayFinally.ToArray();
                    // TitleOfPieSeriesYOY = SetTitleOfPie("规模户同比季度" + this.SelectedIndicator.Value + PieTitleName + "数据和比重示意图(%)");
                    TitleOfPieSeriesYOY = SetTitleOfPie($"规模户{SelectedIndicator.Value}{pieTitleName}去年同期占比图");
                }
                else
                {
                    PieSeriesOfYOY = null;
                    TitleOfPieSeriesYOY = null;
                }


                if (listColumnSeriesValuesIncreaseOfPreConvertToArrayLast  .Count > 0)
                {
                    //直方图标题
                    TitleOfCartNow = GetTitleOfCart($"规模户{SelectedIndicator.Value}环比和同比增量数据");
                    CartSeriesNow = SetColumnsSeries<double, double>($"{SelectedIndicator.Value}环比增量", listColumnSeriesValuesIncreaseOfPreConvertToArrayLast,
                       $"{SelectedIndicator.Value}同比增量", listColumnSeriesValuesIncreaseOfYOYConvertToArrayLast);
                    CartXAxisOfNow = SetColumnsXAxis($"{pieTitleName}名称", listColumnsXAxisNames);
                    CartYAxisOfNow = SetColumnsYAxis(SelectedIndicator.Value + "增量数据");
                }
                else
                {
                    TitleOfCartNow = null;
                    CartXAxisOfNow = null;
                    CartYAxisOfNow = null;
                    CartSeriesNow = null;
                }
                if (listLineSeriesValuesIncreaseOfPreConvertToArrayLast.Count > 0)
                {
                    LineTitle = base.SetTitleOfLine("规模户" + this.SelectedIndicator.Value + pieTitleName + "增幅图(%)");
                    LineSeries = base.SetLineSeries<double, double>(SelectedIndicator.Value + "环比增幅", listLineSeriesValuesIncreaseOfPreConvertToArrayLast,
                        SelectedIndicator.Value + "同比增幅", listLineSeriesValuesIncreaseOfYOYConvertToArrayLast);
                    LineXAxis = SetLineXAxis(pieTitleName + "名称", listLineXAxisNames);
                    LineYAxis = SetLineYAxis(SelectedIndicator.Value + "增幅数据");
                }

                else
                {
                    LineTitle = null;
                    LineXAxis = null;
                    LineYAxis = null;
                    LineSeries = null;
                }
            }
        }





        private async Task ShowPigMassMsgInDataGridAsync()
        {
            if (SelectedCity.Value == null || SelectedCountry.Value == null || SelectedTown.Value == null)
            {
                await MyMessagebox.ShowAsyncInMainWindow("市、县、乡镇至少有一个下拉框未选择内容!", Icon.Error);
                return;
            }
            if (this.SelectedPeriod ==null)
            {
                await MyMessagebox.ShowAsyncInMainWindow("请先选择要展示的时期!", Icon.Error);
                return;
            }
            else if (this.SelectedPeriod.Equals("本季度"))
            {
                await ShowPigMassMsgInDataGridThisSeasonAsync();
            }
            else//如果用户点击的是"1到本季度"
            {
                //先看一下一季度到现在的表是否有缺失
                if (Global.IntSeasonNow==1)
                {
                    await ShowPigMassMsgInDataGridThisSeasonAsync();
                }
                else if(Global.IntSeasonNow==2)//如果是二季度的话
                {
                    //先判断一下表是否存在
                    string[] allNeedTables = new string[] { withYSTableNameNow, withYSTableNamePre };
                    var myDBOperator = MyDBOperator.DBOperatorInstance;
                    var notExistTables = myDBOperator.CheckTablesExist(allNeedTables);
                    string allNotExistTablesJoin = null;
                    if (notExistTables.Count>0)
                    {
                        for (int i = 0; i < notExistTables.Count; i++)
                        {
                            allNotExistTablesJoin += $"、{notExistTables[i].Substring(3)}";
                        }
                        allNotExistTablesJoin = allNotExistTablesJoin.Substring(1);
                        await MyMessagebox.ShowAsyncInMainWindow(allNotExistTablesJoin + "不存在,请先导入", Icon.Warning);
                        return;
                    }
                      
                    //如果没有缺失,需要进行合并
                   await ShowPigMassMsgInDataGridThisYearAsync(allNeedTables,2);
                }
                else if (Global.IntSeasonNow ==3)
                {
                    string[] allNeedTables = new string[] { withYSTableNameNow, withYSTableNamePre,withYSTableNameSpring };
                    var myDBOperator = MyDBOperator.DBOperatorInstance;
                    var notExistTables = myDBOperator.CheckTablesExist(allNeedTables);
                    string allNotExistTablesJoin = null;
                    if (notExistTables.Count > 0)
                    {
                        for (int i = 0; i < notExistTables.Count; i++)
                        {
                            allNotExistTablesJoin += $"、{notExistTables[i].Substring(3)}";
                        }
                        allNotExistTablesJoin = allNotExistTablesJoin.Substring(1);
                        await MyMessagebox.ShowAsyncInMainWindow(allNotExistTablesJoin + "不存在,请先导入", Icon.Warning);
                        return;
                    }
                    await ShowPigMassMsgInDataGridThisYearAsync(allNeedTables, 3);
                }
                else if (Global.IntSeasonNow ==4)
                {
                    string[] allNeedTables = new string[] { withYSTableNameNow, withYSTableNamePre, withYSTableNameSpring,withYSTableNameSummer };
                    var myDBOperator = MyDBOperator.DBOperatorInstance;
                    var notExistTables = myDBOperator.CheckTablesExist(allNeedTables);
                    string allNotExistTablesJoin = null;
                    if (notExistTables.Count > 0)
                    {
                        for (int i = 0; i < notExistTables.Count; i++)
                        {
                            allNotExistTablesJoin += $"、{notExistTables[i].Substring(3)}";
                        }
                        allNotExistTablesJoin = allNotExistTablesJoin.Substring(1);
                        await MyMessagebox.ShowAsyncInMainWindow(allNotExistTablesJoin + "不存在,请先导入", Icon.Warning);
                        return;
                    }
                    await ShowPigMassMsgInDataGridThisYearAsync(allNeedTables, 4);
                }
            }
        }
       
        private async Task ShowPigMassMsgInDataGridThisYearAsync(string[] tableNames,int 期别季)
        {
            MassPigCln.Clear();
            //if (SelectedCity.Value == null || SelectedCountry.Value == null || SelectedTown.Value == null)
            //{
            //    await MyMessagebox.ShowAsyncInMainWindow("市、县、乡镇至少有一个下拉框未选择内容!", Icon.Error);
            //    return;
            //}
            if (SelectedCity.Value.Equals("全部"))//省
            {
           
                DTAll = 生猪规模户信息.GetDTAllIndicatorsOfSubordinateThisYearByCity(tableNames,期别季);
             
                for (int i = 0; i < DTAll.Rows.Count; i++)
                {
                    
                    DataRow row = DTAll.Rows[i];
                    var 市名 = row[0].ToString();
                    var 县名 = "-";
                    var 乡名 = "-";
                    var 户主姓名 = "-";
                    var 养殖户类型 = "-";
                    var 当季出栏数 = Convert.ToDouble(row.IsNull(2) ? 0 : row[2]);
                    var 期末存栏合计 = Convert.ToDouble(row.IsNull(3) ? 0 : row[3]);
                    var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row.IsNull(4) ? 0 : row[4]);
                    var 待育肥猪存栏 = Convert.ToDouble(row.IsNull(5) ? 0 : row[5]);
                    var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row.IsNull(6) ? 0 : row[6]);
                    var 种猪存栏 = Convert.ToDouble(row.IsNull(7) ? 0 : row[7]);
                    var 能繁母猪存栏 = Convert.ToDouble(row.IsNull(8) ? 0 : row[8]);
                    var 当季增加头数 = Convert.ToDouble(row.IsNull(9) ? 0 : row[9]);
                    var 自繁头数 = Convert.ToDouble(row.IsNull(10) ? 0 : row[10]);
                    var 购进头数 = Convert.ToDouble(row.IsNull(11) ? 0 : row[11]);
                    var 当季减少头数 = Convert.ToDouble(row.IsNull(12) ? 0 : row[12]);
                    var 自宰头数 = Convert.ToDouble(row.IsNull(13) ? 0 : row[13]);

                    var 出售肥猪头数 = Convert.ToDouble(row.IsNull(14) ? 0 : row[14]);
                    var 出售肥猪金额 = Convert.ToDouble(row.IsNull(15) ? 0 : row[15]);
                    var 出售肥猪重量 = Convert.ToDouble(row.IsNull(16) ? 0 : row[16]);
                    var 其他原因减少 = Convert.ToDouble(row.IsNull(17) ? 0 : row[17]);
                    var 出售25公斤以下仔猪头数 = Convert.ToDouble(row.IsNull(18) ? 0 : row[18]);
                    var 出售25公斤以下仔猪金额 = Convert.ToDouble(row.IsNull(19) ? 0 : row[19]);
                    var 出售25公斤以下仔猪重量 = Convert.ToDouble(row.IsNull(20) ? 0 : row[20]);

                    MassPigMsgs massPig = new MassPigMsgs(
                        市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                        能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                        其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                    );
                    MassPigCln.Add(massPig);
                }

            }
            else if (SelectedCity.Value.Equals("全部")==false &&SelectedCountry.Value.Equals("全部"))//某个市的
            {
                
                DataTable dt  = 生猪规模户信息.GetDTAllIndicatorsOfSubordinateThisYearByCountry(SelectedCity,tableNames,期别季);
               
                for (global::System.Int32 i = 0; i < dt.Rows.Count; i++)
                {
                   
                    DataRow row = dt.Rows[i];
                    var 市名 = "-";
                    var 县名 = row[0].ToString();
                    var 乡名 = "-";
                    var 户主姓名 = "-";
                    var 养殖户类型 = "-";
                    var 当季出栏数 = Convert.ToDouble(row.IsNull(2) ? 0 : row[2]);
                    var 期末存栏合计 = Convert.ToDouble(row.IsNull(3) ? 0 : row[3]);
                    var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row.IsNull(4) ? 0 : row[4]);
                    var 待育肥猪存栏 = Convert.ToDouble(row.IsNull(5) ? 0 : row[5]);
                    var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row.IsNull(6) ? 0 : row[6]);
                    var 种猪存栏 = Convert.ToDouble(row.IsNull(7) ? 0 : row[7]);
                    var 能繁母猪存栏 = Convert.ToDouble(row.IsNull(8) ? 0 : row[8]);
                    var 当季增加头数 = Convert.ToDouble(row.IsNull(9) ? 0 : row[9]);
                    var 自繁头数 = Convert.ToDouble(row.IsNull(10) ? 0 : row[10]);
                    var 购进头数 = Convert.ToDouble(row.IsNull(11) ? 0 : row[11]);
                    var 当季减少头数 = Convert.ToDouble(row.IsNull(12) ? 0 : row[12]);
                    var 自宰头数 = Convert.ToDouble(row.IsNull(13) ? 0 : row[13]);

                    var 出售肥猪头数 = Convert.ToDouble(row.IsNull(14) ? 0 : row[14]);
                    var 出售肥猪金额 = Convert.ToDouble(row.IsNull(15) ? 0 : row[15]);
                    var 出售肥猪重量 = Convert.ToDouble(row.IsNull(16) ? 0 : row[16]);
                    var 其他原因减少 = Convert.ToDouble(row.IsNull(17) ? 0 : row[17]);
                    var 出售25公斤以下仔猪头数 = Convert.ToDouble(row.IsNull(18) ? 0 : row[18]);
                    var 出售25公斤以下仔猪金额 = Convert.ToDouble(row.IsNull(19) ? 0 : row[19]);
                    var 出售25公斤以下仔猪重量 = Convert.ToDouble(row.IsNull(20) ? 0 : row[20]);

                    MassPigMsgs massPig = new MassPigMsgs(
                        市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                        能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                        其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                    );
                    MassPigCln.Add(massPig);
                }
            }
            else if (SelectedCountry.Equals("全部")==false)//某一个具体县的
            {
                
                DataTable dt = 生猪规模户信息.GetDTAllIndicatorsOfSubordinateThisYearByTown(SelectedCountry, tableNames, 期别季);
               
                for (global::System.Int32 i = 0; i < dt.Rows.Count; i++)
                {
                  
                    DataRow row = dt.Rows[i];
                    var 市名 = "-";
                    var 县名 = "-";
                    var 乡名 = row[0].ToString();
                    var 户主姓名 = "-";
                    var 养殖户类型 = "-";
                    var 当季出栏数 = Convert.ToDouble(row.IsNull(2) ? 0 : row[2]);
                    var 期末存栏合计 = Convert.ToDouble(row.IsNull(3) ? 0 : row[3]);
                    var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row.IsNull(4) ? 0 : row[4]);
                    var 待育肥猪存栏 = Convert.ToDouble(row.IsNull(5) ? 0 : row[5]);
                    var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row.IsNull(6) ? 0 : row[6]);
                    var 种猪存栏 = Convert.ToDouble(row.IsNull(7) ? 0 : row[7]);
                    var 能繁母猪存栏 = Convert.ToDouble(row.IsNull(8) ? 0 : row[8]);
                    var 当季增加头数 = Convert.ToDouble(row.IsNull(9) ? 0 : row[9]);
                    var 自繁头数 = Convert.ToDouble(row.IsNull(10) ? 0 : row[10]);
                    var 购进头数 = Convert.ToDouble(row.IsNull(11) ? 0 : row[11]);
                    var 当季减少头数 = Convert.ToDouble(row.IsNull(12) ? 0 : row[12]);
                    var 自宰头数 = Convert.ToDouble(row.IsNull(13) ? 0 : row[13]);

                    var 出售肥猪头数 = Convert.ToDouble(row.IsNull(14) ? 0 : row[14]);
                    var 出售肥猪金额 = Convert.ToDouble(row.IsNull(15) ? 0 : row[15]);
                    var 出售肥猪重量 = Convert.ToDouble(row.IsNull(16) ? 0 : row[16]);
                    var 其他原因减少 = Convert.ToDouble(row.IsNull(17) ? 0 : row[17]);
                    var 出售25公斤以下仔猪头数 = Convert.ToDouble(row.IsNull(18) ? 0 : row[18]);
                    var 出售25公斤以下仔猪金额 = Convert.ToDouble(row.IsNull(19) ? 0 : row[19]);
                    var 出售25公斤以下仔猪重量 = Convert.ToDouble(row.IsNull(20) ? 0 : row[20]);

                    MassPigMsgs massPig = new MassPigMsgs(
                        市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                        能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                        其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                    );
                    MassPigCln.Add(massPig);
                }

            }
        }
        private async Task ShowPigMassMsgInDataGridThisSeasonAsync()
        {
            try
            {
                MassPigCln.Clear();
                if (SelectedCity.Value == null || SelectedCountry.Value == null || SelectedTown.Value == null)
                {
                    await MyMessagebox.ShowAsyncInMainWindow("市、县、乡镇至少有一个下拉框未选择内容!", Icon.Error);
                    return;
                }
                if (SelectedCity.Value.Equals("全部"))//省
                {
                    DTAll = 生猪规模户信息.GetDTAllIndicatorsOfSubordinateThisSeasonByCity();

                    for (global::System.Int32 i = 0; i < DTAll.Rows.Count; i++)
                    {
                        DataRow row = DTAll.Rows[i];
                        var 市名 = row[0].ToString(); ;
                        var 县名 = "-";
                        var 乡名 = "-";
                        var 户主姓名 = "-";
                        var 养殖户类型 = "-";
                        var 当季出栏数 = Convert.ToDouble(row.IsNull(2) ? 0 : row[2]);
                        var 期末存栏合计 = Convert.ToDouble(row.IsNull(3) ? 0 : row[3]);
                        var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row.IsNull(4) ? 0 : row[4]);
                        var 待育肥猪存栏 = Convert.ToDouble(row.IsNull(5) ? 0 : row[5]);
                        var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row.IsNull(6) ? 0 : row[6]);
                        var 种猪存栏 = Convert.ToDouble(row.IsNull(7) ? 0 : row[7]);
                        var 能繁母猪存栏 = Convert.ToDouble(row.IsNull(8) ? 0 : row[8]);
                        var 当季增加头数 = Convert.ToDouble(row.IsNull(9) ? 0 : row[9]);
                        var 自繁头数 = Convert.ToDouble(row.IsNull(10) ? 0 : row[10]);
                        var 购进头数 = Convert.ToDouble(row.IsNull(11) ? 0 : row[11]);
                        var 当季减少头数 = Convert.ToDouble(row.IsNull(12) ? 0 : row[12]);
                        var 自宰头数 = Convert.ToDouble(row.IsNull(13) ? 0 : row[13]);

                        var 出售肥猪头数 = Convert.ToDouble(row.IsNull(14) ? 0 : row[14]);
                        var 出售肥猪金额 = Convert.ToDouble(row.IsNull(15) ? 0 : row[15]);
                        var 出售肥猪重量 = Convert.ToDouble(row.IsNull(16) ? 0 : row[16]);
                        var 其他原因减少 = Convert.ToDouble(row.IsNull(17) ? 0 : row[17]);
                        var 出售25公斤以下仔猪头数 = Convert.ToDouble(row.IsNull(18) ? 0 : row[18]);
                        var 出售25公斤以下仔猪金额 = Convert.ToDouble(row.IsNull(19) ? 0 : row[19]);
                        var 出售25公斤以下仔猪重量 = Convert.ToDouble(row.IsNull(20) ? 0 : row[20]);

                        MassPigMsgs massPig = new MassPigMsgs(
                            市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                            能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                            其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                        );
                        MassPigCln.Add(massPig);
                    }
                }
                else if (SelectedCity.Value.Equals("全部") == false && SelectedCountry.Value.Equals("全部"))//某个市的
                {
                    DTAll = 生猪规模户信息.GetDTAllIndicatorsOfSubordinateThisSeasonByCountry(SelectedCity);

                    for (global::System.Int32 i = 0; i < DTAll.Rows.Count; i++)
                    {
                        DataRow row = DTAll.Rows[i];
                        var 市名 = "-";
                        var 县名 = row[0].ToString();
                        var 乡名 = "-";
                        var 户主姓名 = "-";
                        var 养殖户类型 = "-";
                        var 当季出栏数 = Convert.ToDouble(row.IsNull(2) ? 0 : row[2]);
                        var 期末存栏合计 = Convert.ToDouble(row.IsNull(3) ? 0 : row[3]);
                        var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row.IsNull(4) ? 0 : row[4]);
                        var 待育肥猪存栏 = Convert.ToDouble(row.IsNull(5) ? 0 : row[5]);
                        var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row.IsNull(6) ? 0 : row[6]);
                        var 种猪存栏 = Convert.ToDouble(row.IsNull(7) ? 0 : row[7]);
                        var 能繁母猪存栏 = Convert.ToDouble(row.IsNull(8) ? 0 : row[8]);
                        var 当季增加头数 = Convert.ToDouble(row.IsNull(9) ? 0 : row[9]);
                        var 自繁头数 = Convert.ToDouble(row.IsNull(10) ? 0 : row[10]);
                        var 购进头数 = Convert.ToDouble(row.IsNull(11) ? 0 : row[11]);
                        var 当季减少头数 = Convert.ToDouble(row.IsNull(12) ? 0 : row[12]);
                        var 自宰头数 = Convert.ToDouble(row.IsNull(13) ? 0 : row[13]);

                        var 出售肥猪头数 = Convert.ToDouble(row.IsNull(14) ? 0 : row[14]);
                        var 出售肥猪金额 = Convert.ToDouble(row.IsNull(15) ? 0 : row[15]);
                        var 出售肥猪重量 = Convert.ToDouble(row.IsNull(16) ? 0 : row[16]);
                        var 其他原因减少 = Convert.ToDouble(row.IsNull(17) ? 0 : row[17]);
                        var 出售25公斤以下仔猪头数 = Convert.ToDouble(row.IsNull(18) ? 0 : row[18]);
                        var 出售25公斤以下仔猪金额 = Convert.ToDouble(row.IsNull(19) ? 0 : row[19]);
                        var 出售25公斤以下仔猪重量 = Convert.ToDouble(row.IsNull(20) ? 0 : row[20]);

                        MassPigMsgs massPig = new MassPigMsgs(
                            市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                            能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                            其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                        );
                        MassPigCln.Add(massPig);
                    }
                }
                else if (SelectedCity.Value.Equals("全部") == false && SelectedCountry.Value.Equals("全部") == false && SelectedTown.Value.Equals("全部"))//某个县分乡镇的
                {
                    DTAll = 生猪规模户信息.GetDTAllIndicatorsOfSubordinateThisSeasonByTown(SelectedCountry);


                    for (global::System.Int32 i = 0; i < DTAll.Rows.Count; i++)
                    {
                        DataRow row = DTAll.Rows[i];
                        var 市名 = "-";
                        var 县名 = "-";
                        var 乡名 = row[0].ToString();
                        var 户主姓名 = "-";
                        var 养殖户类型 = "-";
                        var 当季出栏数 = Convert.ToDouble(row.IsNull(2) ? 0 : row[2]);
                        var 期末存栏合计 = Convert.ToDouble(row.IsNull(3) ? 0 : row[3]);
                        var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row.IsNull(4) ? 0 : row[4]);
                        var 待育肥猪存栏 = Convert.ToDouble(row.IsNull(5) ? 0 : row[5]);
                        var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row.IsNull(6) ? 0 : row[6]);
                        var 种猪存栏 = Convert.ToDouble(row.IsNull(7) ? 0 : row[7]);
                        var 能繁母猪存栏 = Convert.ToDouble(row.IsNull(8) ? 0 : row[8]);
                        var 当季增加头数 = Convert.ToDouble(row.IsNull(9) ? 0 : row[9]);
                        var 自繁头数 = Convert.ToDouble(row.IsNull(10) ? 0 : row[10]);
                        var 购进头数 = Convert.ToDouble(row.IsNull(11) ? 0 : row[11]);
                        var 当季减少头数 = Convert.ToDouble(row.IsNull(12) ? 0 : row[12]);
                        var 自宰头数 = Convert.ToDouble(row.IsNull(13) ? 0 : row[13]);

                        var 出售肥猪头数 = Convert.ToDouble(row.IsNull(14) ? 0 : row[14]);
                        var 出售肥猪金额 = Convert.ToDouble(row.IsNull(15) ? 0 : row[15]);
                        var 出售肥猪重量 = Convert.ToDouble(row.IsNull(16) ? 0 : row[16]);
                        var 其他原因减少 = Convert.ToDouble(row.IsNull(17) ? 0 : row[17]);
                        var 出售25公斤以下仔猪头数 = Convert.ToDouble(row.IsNull(18) ? 0 : row[18]);
                        var 出售25公斤以下仔猪金额 = Convert.ToDouble(row.IsNull(19) ? 0 : row[19]);
                        var 出售25公斤以下仔猪重量 = Convert.ToDouble(row.IsNull(20) ? 0 : row[20]);

                        MassPigMsgs massPig = new MassPigMsgs(
                            市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                            能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                            其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                            );
                        MassPigCln.Add(massPig);
                    }
                }
            }
            catch (Exception ex)
            { 
                StaticLogger.SystemError(ex.Message);
                throw;
            }
        }
        private async void ShowAllMsgs()
        {
            if (SelectedCity.Value == null || SelectedCountry.Value == null || SelectedTown.Value == null)
            {
                await MyMessagebox.ShowAsyncInMainWindow("市、县、乡镇至少有一个下拉框未选择内容!", Icon.Error);
                return;
            }
            //List<string> ListStrSumAllIndicators = new List<string>();
            //string sqlToGetAllSumIndicators = string.Empty;
            //for (int i = 0; i < _arrStrIndicatorsOfPig.Length; i++)
            //{
            //    ListStrSumAllIndicators.Add($"SUM([{_arrStrIndicatorsOfPig[i]}]) as [规模户{_arrStrIndicatorsOfPig[i]}]");
            //}
            //string StrAllIndicatorsSumJoin = string.Join(",", ListStrSumAllIndicators);
            //if (SelectedCity.Equals("全部"))
            //{
            //    sqlToGetAllSumIndicators = $"s"
            //}


            DTAll = showMsg.GetDtAllMsgs(SelectedCity, SelectedCountry, SelectedTown, "猪", withYSTableNameNow);
            MassPigCln.Clear();
            if (DTAll.Rows.Count > 0)
            {
                if (DTAll.Columns.Contains("市") == true)
                {


                    for (global::System.Int32 i = 0; i < DTAll.Rows.Count; i++)
                    {
                        DataRow row = DTAll.Rows[i];
                        var 市名 = row[0].ToString(); ;
                        var 县名 = "-";
                        var 乡名 = "-";
                        var 户主姓名 = "-";
                        var 养殖户类型 = "-";
                        var 当季出栏数 = Convert.ToDouble(row.IsNull(2) ? 0 : row[2]);
                        var 期末存栏合计 = Convert.ToDouble(row.IsNull(3) ? 0 : row[3]);
                        var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row.IsNull(4) ? 0 : row[4]);
                        var 待育肥猪存栏 = Convert.ToDouble(row.IsNull(5) ? 0 : row[5]);
                        var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row.IsNull(6) ? 0 : row[6]);
                        var 种猪存栏 = Convert.ToDouble(row.IsNull(7) ? 0 : row[7]);
                        var 能繁母猪存栏 = Convert.ToDouble(row.IsNull(8) ? 0 : row[8]);
                        var 当季增加头数 = Convert.ToDouble(row.IsNull(9) ? 0 : row[9]);
                        var 自繁头数 = Convert.ToDouble(row.IsNull(10) ? 0 : row[10]);
                        var 购进头数 = Convert.ToDouble(row.IsNull(11) ? 0 : row[11]);
                        var 当季减少头数 = Convert.ToDouble(row.IsNull(12) ? 0 : row[12]);
                        var 自宰头数 = Convert.ToDouble(row.IsNull(13) ? 0 : row[13]);

                        var 出售肥猪头数 = Convert.ToDouble(row.IsNull(14) ? 0 : row[14]);
                        var 出售肥猪金额 = Convert.ToDouble(row.IsNull(15) ? 0 : row[15]);
                        var 出售肥猪重量 = Convert.ToDouble(row.IsNull(16) ? 0 : row[16]);
                        var 其他原因减少 = Convert.ToDouble(row.IsNull(17) ? 0 : row[17]);
                        var 出售25公斤以下仔猪头数 = Convert.ToDouble(row.IsNull(18) ? 0 : row[18]);
                        var 出售25公斤以下仔猪金额 = Convert.ToDouble(row.IsNull(19) ? 0 : row[19]);
                        var 出售25公斤以下仔猪重量 = Convert.ToDouble(row.IsNull(20) ? 0 : row[20]);

                        MassPigMsgs massPig = new MassPigMsgs(
                            市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                            能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                            其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                        );
                        MassPigCln.Add(massPig);
                    }
                }
                else if (DTAll.Columns.Contains("乡") == true)
                {


                    for (global::System.Int32 i = 0; i < DTAll.Rows.Count; i++)
                    {
                        DataRow row = DTAll.Rows[i];
                        var 市名 = "-";
                        var 县名 = "-";
                        var 乡名 = row[0].ToString();
                        var 户主姓名 = "-";
                        var 养殖户类型 = "-";
                        var 当季出栏数 = Convert.ToDouble(row.IsNull(2) ? 0 : row[2]);
                        var 期末存栏合计 = Convert.ToDouble(row.IsNull(3) ? 0 : row[3]);
                        var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row.IsNull(4) ? 0 : row[4]);
                        var 待育肥猪存栏 = Convert.ToDouble(row.IsNull(5) ? 0 : row[5]);
                        var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row.IsNull(6) ? 0 : row[6]);
                        var 种猪存栏 = Convert.ToDouble(row.IsNull(7) ? 0 : row[7]);
                        var 能繁母猪存栏 = Convert.ToDouble(row.IsNull(8) ? 0 : row[8]);
                        var 当季增加头数 = Convert.ToDouble(row.IsNull(9) ? 0 : row[9]);
                        var 自繁头数 = Convert.ToDouble(row.IsNull(10) ? 0 : row[10]);
                        var 购进头数 = Convert.ToDouble(row.IsNull(11) ? 0 : row[11]);
                        var 当季减少头数 = Convert.ToDouble(row.IsNull(12) ? 0 : row[12]);
                        var 自宰头数 = Convert.ToDouble(row.IsNull(13) ? 0 : row[13]);

                        var 出售肥猪头数 = Convert.ToDouble(row.IsNull(14) ? 0 : row[14]);
                        var 出售肥猪金额 = Convert.ToDouble(row.IsNull(15) ? 0 : row[15]);
                        var 出售肥猪重量 = Convert.ToDouble(row.IsNull(16) ? 0 : row[16]);
                        var 其他原因减少 = Convert.ToDouble(row.IsNull(17) ? 0 : row[17]);
                        var 出售25公斤以下仔猪头数 = Convert.ToDouble(row.IsNull(18) ? 0 : row[18]);
                        var 出售25公斤以下仔猪金额 = Convert.ToDouble(row.IsNull(19) ? 0 : row[19]);
                        var 出售25公斤以下仔猪重量 = Convert.ToDouble(row.IsNull(20) ? 0 : row[20]);

                        MassPigMsgs massPig = new MassPigMsgs(
                            市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                            能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                            其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                            );
                        MassPigCln.Add(massPig);
                    }
                }
                else if (DTAll.Columns.Contains("县") && DTAll.Columns.Contains("户主姓名") == false)
                {
                    for (global::System.Int32 i = 0; i < DTAll.Rows.Count; i++)
                    {
                        DataRow row = DTAll.Rows[i];
                        var 市名 = "-";
                        var 县名 = row[0].ToString();
                        var 乡名 = "-";
                        var 户主姓名 = "-";
                        var 养殖户类型 = "-";
                        var 当季出栏数 = Convert.ToDouble(row.IsNull(2) ? 0 : row[2]);
                        var 期末存栏合计 = Convert.ToDouble(row.IsNull(3) ? 0 : row[3]);
                        var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row.IsNull(4) ? 0 : row[4]);
                        var 待育肥猪存栏 = Convert.ToDouble(row.IsNull(5) ? 0 : row[5]);
                        var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row.IsNull(6) ? 0 : row[6]);
                        var 种猪存栏 = Convert.ToDouble(row.IsNull(7) ? 0 : row[7]);
                        var 能繁母猪存栏 = Convert.ToDouble(row.IsNull(8) ? 0 : row[8]);
                        var 当季增加头数 = Convert.ToDouble(row.IsNull(9) ? 0 : row[9]);
                        var 自繁头数 = Convert.ToDouble(row.IsNull(10) ? 0 : row[10]);
                        var 购进头数 = Convert.ToDouble(row.IsNull(11) ? 0 : row[11]);
                        var 当季减少头数 = Convert.ToDouble(row.IsNull(12) ? 0 : row[12]);
                        var 自宰头数 = Convert.ToDouble(row.IsNull(13) ? 0 : row[13]);

                        var 出售肥猪头数 = Convert.ToDouble(row.IsNull(14) ? 0 : row[14]);
                        var 出售肥猪金额 = Convert.ToDouble(row.IsNull(15) ? 0 : row[15]);
                        var 出售肥猪重量 = Convert.ToDouble(row.IsNull(16) ? 0 : row[16]);
                        var 其他原因减少 = Convert.ToDouble(row.IsNull(17) ? 0 : row[17]);
                        var 出售25公斤以下仔猪头数 = Convert.ToDouble(row.IsNull(18) ? 0 : row[18]);
                        var 出售25公斤以下仔猪金额 = Convert.ToDouble(row.IsNull(19) ? 0 : row[19]);
                        var 出售25公斤以下仔猪重量 = Convert.ToDouble(row.IsNull(20) ? 0 : row[20]);

                        MassPigMsgs massPig = new MassPigMsgs(
                            市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                            能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                            其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                        );
                        MassPigCln.Add(massPig);
                    }
                }
            }
        }
        public async Task ShowMsgByAllFarmersInDataGridAsync()
        {

            if (SelectedCity.Value == null || SelectedCountry.Value == null || SelectedTown.Value == null)
            {
                await MyMessagebox.ShowAsyncInMainWindow("市、县、乡镇至少有一个下拉框未选择内容!", Icon.Error);
                return;
            }
            if (this.SelectedPeriod == null)
            {
                await MyMessagebox.ShowAsyncInMainWindow("请先选择要展示的时期!", Icon.Error);
                return;
            }
            else if (this.SelectedPeriod.Equals("本季度"))
            {
                await ShowMsgByAllFarmerInDataGridThisSeasonAsync();
            }
            else//如果用户点击的是"1到本季度"
            {
                //先看一下一季度到现在的表是否有缺失
                if (Global.IntSeasonNow == 1)
                {
                    await ShowMsgByAllFarmerInDataGridThisSeasonAsync();
                }
                else if (Global.IntSeasonNow == 2)//如果是二季度的话
                {
                    //先判断一下表是否存在
                    string[] allNeedTables = new string[] { withYSTableNameNow, withYSTableNamePre };
                    var myDBOperator = MyDBOperator.DBOperatorInstance;
                    var notExistTables = myDBOperator.CheckTablesExist(allNeedTables);
                    string allNotExistTablesJoin = null;
                    if (notExistTables.Count > 0)
                    {
                        for (int i = 0; i < notExistTables.Count; i++)
                        {
                            allNotExistTablesJoin += $"、{notExistTables[i].Substring(3)}";
                        }
                        allNotExistTablesJoin = allNotExistTablesJoin.Substring(1);
                        await MyMessagebox.ShowAsyncInMainWindow(allNotExistTablesJoin + "不存在,请先导入", Icon.Warning);
                        return;
                    }

                    //如果没有缺失,需要进行合并
                    await ShowMsgByAllFarmerInDataGridThisYearAsync(allNeedTables, 2);
                }
                else if (Global.IntSeasonNow == 3)
                {
                    string[] allNeedTables = new string[] { withYSTableNameNow, withYSTableNamePre, withYSTableNameSpring };
                    var myDBOperator = MyDBOperator.DBOperatorInstance;
                    var notExistTables = myDBOperator.CheckTablesExist(allNeedTables);
                    string allNotExistTablesJoin = null;
                    if (notExistTables.Count > 0)
                    {
                        for (int i = 0; i < notExistTables.Count; i++)
                        {
                            allNotExistTablesJoin += $"、{notExistTables[i].Substring(3)}";
                        }
                        allNotExistTablesJoin = allNotExistTablesJoin.Substring(1);
                        await MyMessagebox.ShowAsyncInMainWindow(allNotExistTablesJoin + "不存在,请先导入", Icon.Warning);
                        return;
                    }
                    await ShowMsgByAllFarmerInDataGridThisYearAsync(allNeedTables, 3);
                }
                else if (Global.IntSeasonNow == 4)
                {
                    string[] allNeedTables = new string[] { withYSTableNameNow, withYSTableNamePre, withYSTableNameSpring, withYSTableNameSummer };
                    var myDBOperator = MyDBOperator.DBOperatorInstance;
                    var notExistTables = myDBOperator.CheckTablesExist(allNeedTables);
                    string allNotExistTablesJoin = null;
                    if (notExistTables.Count > 0)
                    {
                        for (int i = 0; i < notExistTables.Count; i++)
                        {
                            allNotExistTablesJoin += $"、{notExistTables[i].Substring(3)}";
                        }
                        allNotExistTablesJoin = allNotExistTablesJoin.Substring(1);
                        await MyMessagebox.ShowAsyncInMainWindow(allNotExistTablesJoin + "不存在,请先导入", Icon.Warning);
                        return;
                    }
                    await ShowMsgByAllFarmerInDataGridThisYearAsync(allNeedTables, 4);
                }
            }

        }

        private async Task ShowMsgByAllFarmerInDataGridThisYearAsync(string[] tableNames, int 期别季)
        {
            //throw new NotImplementedException();
            MassPigCln.Clear();
         
            if (SelectedCity.Value.Equals("全部"))//省
            {
                DataTable dt = 生猪规模户信息.GetDTOfAllFarmersThisYearOfProvince(tableNames,期别季);
                
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                   
                    DataRow row = dt.Rows[i];
                    var 市名 = row[0].ToString();
                    var 县名 = row[2].ToString();
                    var 乡名 = row[4].ToString();
                    var 户主姓名 = row[7].ToString();
                    var 养殖户类型 = row[8].ToString();
                    var 当季出栏数 = Convert.ToDouble(row[9].ToString() ?? "0");
                    var 期末存栏合计 = Convert.ToDouble(row[10].ToString() ?? "0");
                    var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row[11].ToString() ?? "0");
                    var 待育肥猪存栏 = Convert.ToDouble(row[12].ToString() ?? "0");
                    var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row[13].ToString() ?? "0");
                    var 种猪存栏 = Convert.ToDouble(row[14].ToString() ?? "0");
                    var 能繁母猪存栏 = Convert.ToDouble(row[15].ToString() ?? "0");
                    var 当季增加头数 = Convert.ToDouble(row[16].ToString() ?? "0");
                    var 自繁头数 = Convert.ToDouble(row[17].ToString() ?? "0");
                    var 购进头数 = Convert.ToDouble(row[18].ToString() ?? "0");
                    var 当季减少头数 = Convert.ToDouble(row[19].ToString() ?? "0");
                    var 自宰头数 = Convert.ToDouble(row[20].ToString() ?? "0");

                    var 出售肥猪头数 = Convert.ToDouble(row[21].ToString() ?? "0");
                    var 出售肥猪金额 = Convert.ToDouble(row[22].ToString() ?? "0");
                    var 出售肥猪重量 = Convert.ToDouble(row[23].ToString() ?? "0");
                    var 其他原因减少 = Convert.ToDouble(row[24].ToString() ?? "0");
                    var 出售25公斤以下仔猪头数 = Convert.ToDouble(row[25].ToString() ?? "0");
                    var 出售25公斤以下仔猪金额 = Convert.ToDouble(row[26].ToString() ?? "0");
                    var 出售25公斤以下仔猪重量 = Convert.ToDouble(row[27].ToString() ?? "0");

                    MassPigMsgs massPig = new MassPigMsgs(
                        市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                        能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                        其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                    );
                    MassPigCln.Add(massPig);
                }

            }
            else if (SelectedCity.Value.Equals("全部") == false && SelectedCountry.Value.Equals("全部"))//某个市的
            {
                DataTable dt = 生猪规模户信息.GetDTOfAllFarmersThisYearOfCity(SelectedCity, tableNames, 期别季);

                for (int i = 0; i < dt.Rows.Count; i++)
                {

                    DataRow row = dt.Rows[i];
                    var 市名 = row[0].ToString();
                    var 县名 = row[2].ToString();
                    var 乡名 = row[4].ToString();
                    var 户主姓名 = row[7].ToString();
                    var 养殖户类型 = row[8].ToString();
                    var 当季出栏数 = Convert.ToDouble(row[9].ToString() ?? "0");
                    var 期末存栏合计 = Convert.ToDouble(row[10].ToString() ?? "0");
                    var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row[11].ToString() ?? "0");
                    var 待育肥猪存栏 = Convert.ToDouble(row[12].ToString() ?? "0");
                    var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row[13].ToString() ?? "0");
                    var 种猪存栏 = Convert.ToDouble(row[14].ToString() ?? "0");
                    var 能繁母猪存栏 = Convert.ToDouble(row[15].ToString() ?? "0");
                    var 当季增加头数 = Convert.ToDouble(row[16].ToString() ?? "0");
                    var 自繁头数 = Convert.ToDouble(row[17].ToString() ?? "0");
                    var 购进头数 = Convert.ToDouble(row[18].ToString() ?? "0");
                    var 当季减少头数 = Convert.ToDouble(row[19].ToString() ?? "0");
                    var 自宰头数 = Convert.ToDouble(row[20].ToString() ?? "0");

                    var 出售肥猪头数 = Convert.ToDouble(row[21].ToString() ?? "0");
                    var 出售肥猪金额 = Convert.ToDouble(row[22].ToString() ?? "0");
                    var 出售肥猪重量 = Convert.ToDouble(row[23].ToString() ?? "0");
                    var 其他原因减少 = Convert.ToDouble(row[24].ToString() ?? "0");
                    var 出售25公斤以下仔猪头数 = Convert.ToDouble(row[25].ToString() ?? "0");
                    var 出售25公斤以下仔猪金额 = Convert.ToDouble(row[26].ToString() ?? "0");
                    var 出售25公斤以下仔猪重量 = Convert.ToDouble(row[27].ToString() ?? "0");

                    MassPigMsgs massPig = new MassPigMsgs(
                        市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                        能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                        其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                    );
                    MassPigCln.Add(massPig);
                }
            }
            else if (SelectedCountry.Value.Equals("全部") == false && SelectedTown.Value.Equals("全部"))//某一个具体县的
            {
                DataTable dt = 生猪规模户信息.GetDTOfAllFarmersThisYearOfCountry(SelectedCountry, tableNames, 期别季);

                for (int i = 0; i < dt.Rows.Count; i++)
                {

                    DataRow row = dt.Rows[i];
                    var 市名 = row[0].ToString();
                    var 县名 = row[2].ToString();
                    var 乡名 = row[4].ToString();
                    var 户主姓名 = row[7].ToString();
                    var 养殖户类型 = row[8].ToString();
                    var 当季出栏数 = Convert.ToDouble(row[9].ToString() ?? "0");
                    var 期末存栏合计 = Convert.ToDouble(row[10].ToString() ?? "0");
                    var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row[11].ToString() ?? "0");
                    var 待育肥猪存栏 = Convert.ToDouble(row[12].ToString() ?? "0");
                    var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row[13].ToString() ?? "0");
                    var 种猪存栏 = Convert.ToDouble(row[14].ToString() ?? "0");
                    var 能繁母猪存栏 = Convert.ToDouble(row[15].ToString() ?? "0");
                    var 当季增加头数 = Convert.ToDouble(row[16].ToString() ?? "0");
                    var 自繁头数 = Convert.ToDouble(row[17].ToString() ?? "0");
                    var 购进头数 = Convert.ToDouble(row[18].ToString() ?? "0");
                    var 当季减少头数 = Convert.ToDouble(row[19].ToString() ?? "0");
                    var 自宰头数 = Convert.ToDouble(row[20].ToString() ?? "0");

                    var 出售肥猪头数 = Convert.ToDouble(row[21].ToString() ?? "0");
                    var 出售肥猪金额 = Convert.ToDouble(row[22].ToString() ?? "0");
                    var 出售肥猪重量 = Convert.ToDouble(row[23].ToString() ?? "0");
                    var 其他原因减少 = Convert.ToDouble(row[24].ToString() ?? "0");
                    var 出售25公斤以下仔猪头数 = Convert.ToDouble(row[25].ToString() ?? "0");
                    var 出售25公斤以下仔猪金额 = Convert.ToDouble(row[26].ToString() ?? "0");
                    var 出售25公斤以下仔猪重量 = Convert.ToDouble(row[27].ToString() ?? "0");

                    MassPigMsgs massPig = new MassPigMsgs(
                        市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                        能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                        其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                    );
                    MassPigCln.Add(massPig);
                }

            }
            else if (SelectedCountry.Value.Equals("全部") ==false &&  SelectedTown.Value.Equals("全部")==false )//某一个具体乡镇的
            {
                DataTable dt = 生猪规模户信息.GetDTOfAllFarmersThisYearOfTown(SelectedTown, tableNames, 期别季);

                for (int i = 0; i < dt.Rows.Count; i++)
                {

                    DataRow row = dt.Rows[i];
                    var 市名 = row[0].ToString();
                    var 县名 = row[2].ToString();
                    var 乡名 = row[4].ToString();
                    var 户主姓名 = row[7].ToString();
                    var 养殖户类型 = row[8].ToString();
                    var 当季出栏数 = Convert.ToDouble(row[9].ToString() ?? "0");
                    var 期末存栏合计 = Convert.ToDouble(row[10].ToString() ?? "0");
                    var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row[11].ToString() ?? "0");
                    var 待育肥猪存栏 = Convert.ToDouble(row[12].ToString() ?? "0");
                    var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row[13].ToString() ?? "0");
                    var 种猪存栏 = Convert.ToDouble(row[14].ToString() ?? "0");
                    var 能繁母猪存栏 = Convert.ToDouble(row[15].ToString() ?? "0");
                    var 当季增加头数 = Convert.ToDouble(row[16].ToString() ?? "0");
                    var 自繁头数 = Convert.ToDouble(row[17].ToString() ?? "0");
                    var 购进头数 = Convert.ToDouble(row[18].ToString() ?? "0");
                    var 当季减少头数 = Convert.ToDouble(row[19].ToString() ?? "0");
                    var 自宰头数 = Convert.ToDouble(row[20].ToString() ?? "0");

                    var 出售肥猪头数 = Convert.ToDouble(row[21].ToString() ?? "0");
                    var 出售肥猪金额 = Convert.ToDouble(row[22].ToString() ?? "0");
                    var 出售肥猪重量 = Convert.ToDouble(row[23].ToString() ?? "0");
                    var 其他原因减少 = Convert.ToDouble(row[24].ToString() ?? "0");
                    var 出售25公斤以下仔猪头数 = Convert.ToDouble(row[25].ToString() ?? "0");
                    var 出售25公斤以下仔猪金额 = Convert.ToDouble(row[26].ToString() ?? "0");
                    var 出售25公斤以下仔猪重量 = Convert.ToDouble(row[27].ToString() ?? "0");

                    MassPigMsgs massPig = new MassPigMsgs(
                        市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                        能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                        其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                    );
                    MassPigCln.Add(massPig);
                }

            }
        }

        /// <summary>
        /// 展示本季度所有养殖户的情况
        /// </summary>
        /// <returns></returns>
        private async Task ShowMsgByAllFarmerInDataGridThisSeasonAsync()
        {
            MassPigCln.Clear();
            DataTable dt = new DataTable();
            //if (SelectedCity.Value == null || SelectedCountry.Value == null || SelectedTown.Value == null)
            //{
            //    await MyMessagebox.ShowAsyncInMainWindow("市、县、乡镇至少有一个下拉框未选择内容!", Icon.Error);
            //    return;
            //}
            if (SelectedCity.Value.Equals("全部"))//省
            {
                dt = 生猪规模户信息.GetDTAllIndicatorsOfAllOwnersLocalThisSeasonByCity();
            }
            else if (SelectedCity.Value.Equals("全部")==false && SelectedCountry.Value.Equals("全部"))//某个市的
            {
                dt = 生猪规模户信息.GetDTAllIndicatorsOfAllOwnersLocalThisSeasonByCountry(SelectedCity);
            }
            else if (SelectedCity.Value.Equals("全部") == false && SelectedCountry.Value.Equals("全部")==false && SelectedTown.Value.Equals("全部"))//某个县的
            {
                dt = 生猪规模户信息.GetDTAllIndicatorsOfAllOwnersLocalThisSeasonByTown(SelectedCountry);
            }
            else
            {
                dt= 生猪规模户信息.GetDTAllIndicatorsOfAllOwnersLocalThisSeasonOfASelectedTown(SelectedTown);
            }
            if (dt.Rows.Count > 0)
            {

                for (global::System.Int32 i = 0; i <dt.Rows.Count; i++)
                {
                    DataRow row = dt.Rows[i];
                    var 市名 = row[0].ToString();
                    var 县名 = row[1].ToString();
                    var 乡名 = row[2].ToString();
                    var 户主姓名 = row[3].ToString(); ;
                    var 养殖户类型 = row[4].ToString(); ;
                    var 当季出栏数 = Convert.ToDouble(row[5].ToString() ?? "0");
                    var 期末存栏合计 = Convert.ToDouble(row[6].ToString() ?? "0");
                    var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row[7].ToString() ?? "0");
                    var 待育肥猪存栏 = Convert.ToDouble(row[8].ToString() ?? "0");
                    var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row[9].ToString() ?? "0");
                    var 种猪存栏 = Convert.ToDouble(row[10].ToString() ?? "0");
                    var 能繁母猪存栏 = Convert.ToDouble(row[11].ToString() ?? "0");
                    var 当季增加头数 = Convert.ToDouble(row[12].ToString() ?? "0");
                    var 自繁头数 = Convert.ToDouble(row[13].ToString() ?? "0");
                    var 购进头数 = Convert.ToDouble(row[14].ToString() ?? "0");
                    var 当季减少头数 = Convert.ToDouble(row[15].ToString() ?? "0");
                    var 自宰头数 = Convert.ToDouble(row[16].ToString() ?? "0");

                    var 出售肥猪头数 = Convert.ToDouble(row[17].ToString() ?? "0");
                    var 出售肥猪金额 = Convert.ToDouble(row[18].ToString() ?? "0");
                    var 出售肥猪重量 = Convert.ToDouble(row[19].ToString() ?? "0");
                    var 其他原因减少 = Convert.ToDouble(row[20].ToString() ?? "0");
                    var 出售25公斤以下仔猪头数 = Convert.ToDouble(row[21].ToString() ?? "0");
                    var 出售25公斤以下仔猪金额 = Convert.ToDouble(row[22].ToString() ?? "0");
                    var 出售25公斤以下仔猪重量 = Convert.ToDouble(row[23].ToString() ?? "0");
                    MassPigMsgs massPig = new MassPigMsgs(
                   市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                   能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                   其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                   );
                    MassPigCln.Add(massPig);
                }
            }
        }

        private async void ShowAllOwnerMsg()
        {
            if (SelectedCity.Value == null || SelectedCountry.Value == null || SelectedTown.Value == null)
            {
                await MyMessagebox.ShowAsyncInMainWindow("市、县、乡镇至少有一个下拉框未选择内容!", MsBox.Avalonia.Enums.Icon.Error);

                return;
            }
            DataTable dt = showMsg.GetAllOwnerMsg(SelectedCity, SelectedCountry, SelectedTown, "猪", withYSTableNameNow);
            if (dt != null)
            {
                DTAll = showMsg.GetAllOwnerMsg(SelectedCity, SelectedCountry, SelectedTown, "猪", withYSTableNameNow);
                MassPigCln.Clear();
                if (DTAll.Rows.Count > 0)
                {

                    for (global::System.Int32 i = 0; i < DTAll.Rows.Count; i++)
                    {
                        DataRow row = DTAll.Rows[i];
                        var 市名 = row[0].ToString();
                        var 县名 = row[1].ToString();
                        var 乡名 = row[2].ToString();
                        var 户主姓名 = row[3].ToString(); ;
                        var 养殖户类型 = row[4].ToString(); ;
                        var 当季出栏数 = Convert.ToDouble(row[5].ToString() ?? "0");
                        var 期末存栏合计 = Convert.ToDouble(row[6].ToString() ?? "0");
                        var 二十五公斤以下仔猪存栏 = Convert.ToDouble(row[7].ToString() ?? "0");
                        var 待育肥猪存栏 = Convert.ToDouble(row[8].ToString() ?? "0");
                        var 五十公斤以上待育肥猪存栏 = Convert.ToDouble(row[9].ToString() ?? "0");
                        var 种猪存栏 = Convert.ToDouble(row[10].ToString() ?? "0");
                        var 能繁母猪存栏 = Convert.ToDouble(row[11].ToString() ?? "0");
                        var 当季增加头数 = Convert.ToDouble(row[12].ToString() ?? "0");
                        var 自繁头数 = Convert.ToDouble(row[13].ToString() ?? "0");
                        var 购进头数 = Convert.ToDouble(row[14].ToString() ?? "0");
                        var 当季减少头数 = Convert.ToDouble(row[15].ToString() ?? "0");
                        var 自宰头数 = Convert.ToDouble(row[16].ToString() ?? "0");

                        var 出售肥猪头数 = Convert.ToDouble(row[17].ToString() ?? "0");
                        var 出售肥猪金额 = Convert.ToDouble(row[18].ToString() ?? "0");
                        var 出售肥猪重量 = Convert.ToDouble(row[19].ToString() ?? "0");
                        var 其他原因减少 = Convert.ToDouble(row[20].ToString() ?? "0");
                        var 出售25公斤以下仔猪头数 = Convert.ToDouble(row[21].ToString() ?? "0");
                        var 出售25公斤以下仔猪金额 = Convert.ToDouble(row[22].ToString() ?? "0");
                        var 出售25公斤以下仔猪重量 = Convert.ToDouble(row[23].ToString() ?? "0");
                        MassPigMsgs massPig = new MassPigMsgs(
                       市名, 县名, 乡名, 户主姓名, 养殖户类型, 当季出栏数, 期末存栏合计, 二十五公斤以下仔猪存栏, 待育肥猪存栏, 五十公斤以上待育肥猪存栏, 种猪存栏,
                       能繁母猪存栏, 当季增加头数, 自繁头数, 购进头数, 当季减少头数, 自宰头数, 出售肥猪头数, 出售肥猪金额, 出售肥猪重量,
                       其他原因减少, 出售25公斤以下仔猪头数, 出售25公斤以下仔猪金额, 出售25公斤以下仔猪重量
                       );
                        MassPigCln.Add(massPig);
                    }
                }
            }
            else
            {
                await MyMessagebox.ShowAsyncInMainWindow("如要查看选中乡镇的分户数据,请点击左侧的按钮", MsBox.Avalonia.Enums.Icon.Info);

            }


        }





        private async void ShowSingleMsgOnlyNow()
        {
            if (SelectedCity.Value == null || SelectedCountry.Value == null || SelectedTown.Value == null)
            {
                await MyMessagebox.ShowAsyncInMainWindow("市、县、乡镇至少有一个下拉框未选择内容!", Icon.Error);

                return;
            }
            if (string.IsNullOrEmpty(SelectedIndicator.Value))
            {
                await MyMessagebox.ShowAsyncInMainWindow("未选择具体指标名称!", Icon.Warning);
                return;
            }
            if (DTAll != null)
            {
                List<ISeries> CircleConsistOfPiecesOfIndicatorOnlyNowConvertToArrayFinally = new List<ISeries>();
                List<double> ListColumnSeriesValuesIncreaseOfPreConvertToArryLast = new List<double>();
                List<double> ListLineSeriesValuesIncreaseOfPreConvertToArrayLast = new List<double>();
                List<string> ColumnsXAxisNames = new List<string>();
                List<string> ListLineXAxisNames = new List<string>();
                //var linqValues = DTAll.AsEnumerable().Select(r => r.Field<double>($"{SelectedIndicator}")).ToList();
                //var names = DTAll.AsEnumerable().Select(r => r.Field<double>($"乡镇")).ToList();
                for (int i = 0; i < DTAll.Rows.Count - 1; i++)
                {
                    DataRow row = DTAll.Rows[i];
                    var linqvalue = row.Field<double>($"规模户{SelectedIndicator.Value}");
                    string name = row.Field<string>("乡");
                    AddOnePieSeriesToCircleList(linqvalue, name, ref CircleConsistOfPiecesOfIndicatorOnlyNowConvertToArrayFinally);
                    AddOneColumnToCart(row, $"规模户{SelectedIndicator.Value}", "乡", ref ListColumnSeriesValuesIncreaseOfPreConvertToArryLast, ref ColumnsXAxisNames);
                    AddOneColumnToCart(row, $"规模户{SelectedIndicator.Value}", "乡", ref ListLineSeriesValuesIncreaseOfPreConvertToArrayLast, ref ListLineXAxisNames);
                }
                if (CircleConsistOfPiecesOfIndicatorOnlyNowConvertToArrayFinally.Count > 0)
                {
                    PieSeriesOfNow = CircleConsistOfPiecesOfIndicatorOnlyNowConvertToArrayFinally.ToArray();
                    TitleOfPieSeriesNow = SetTitleOfPie($"规模户{SelectedIndicator.Value}分布图");

                }
                if (ListColumnSeriesValuesIncreaseOfPreConvertToArryLast.Count > 0)
                {
                    //直方图标题
                    TitleOfCartNow = GetTitleOfCart($"规模户{SelectedIndicator.Value}数据情况");
                    CartSeriesNow = SetColumnsSeries<double>($"{SelectedIndicator.Value}数据情况", ListColumnSeriesValuesIncreaseOfPreConvertToArryLast
                       );
                    CartXAxisOfNow = SetColumnsXAxis($"分乡镇名称", ColumnsXAxisNames);
                    CartYAxisOfNow = SetColumnsYAxis(SelectedIndicator.Value + "数据");
                }
                if (ListLineSeriesValuesIncreaseOfPreConvertToArrayLast.Count > 0)
                {
                    LineTitle = base.SetTitleOfLine("规模户" + this.SelectedIndicator.Value + "情况");
                    LineSeries = SetLineSeries<double>(SelectedIndicator.Value + "环比增幅", ListLineSeriesValuesIncreaseOfPreConvertToArrayLast);
                    LineXAxis = SetLineXAxis("分乡镇名称", ListLineXAxisNames);
                    LineYAxis = SetLineYAxis(SelectedIndicator.Value + "数据");
                }
            }
        }
        public ISeries[] SetLineSeries<T>(string name1, List<T> ListLineSeriesValues1)
        {
            ISeries[] LineSeries = new ISeries[]
            {
                new LineSeries<T>()
                {
                    Name =name1,
                    Values = ListLineSeriesValues1.ToArray() ,
                    Fill = null,
                    DataLabelsFormatter =  point => point.Coordinate.PrimaryValue.ToString(""),
                    DataLabelsPaint = new SolidColorPaint(SKColors.Black),
                    DataLabelsPosition = DataLabelsPosition.Top,
                    ScalesXAt = 0,
                    DataLabelsPadding = new Padding(5.0,5.0, 5.0, 5.0),
                    DataPadding = new LiveChartsCore.Drawing.LvcPoint(1.0, 1.0),
                },

            };
            return LineSeries;
        }
        public ISeries[] SetColumnsSeries<T1>(string name1, List<T1> ListColumnsValues1)
        {
            ISeries[] ColumsSeries = new ISeries[]
            {
               new ColumnSeries<T1>()
               {
                    Name = name1,
                    Values = ListColumnsValues1.ToArray(),
                    Padding = 5,
                    MaxBarWidth = 30,
                    DataLabelsPosition = DataLabelsPosition.Middle,
                    DataLabelsSize = 10,
                    DataLabelsFormatter = poin => poin.Coordinate.PrimaryValue.ToString(""),//c2是转成金额,并显示到第二位小数 c是转成基恩个,显示一位小数
                    ScalesYAt = 0,
                    DataLabelsPaint = new SolidColorPaint{
                        Color = SKColors.Black,
                        SKTypeface = SKFontManager.Default.MatchCharacter('汉')
                    },
               },

            };
            return ColumsSeries;
        }

        protected void AddOneColumnToCart(DataRow row, string columnName, string legendName, ref List<double> ListOfNo1ColumnSeriesValues, ref List<string> ColumnsXAxisNames)
        {
            if (row.IsNull(columnName))
            {
                ListOfNo1ColumnSeriesValues.Add(0d);
            }
            else
            {
                ListOfNo1ColumnSeriesValues.Add((double)row[columnName]);
            }
            ColumnsXAxisNames.Add(row[legendName].ToString());
        }
        protected void AddOnePieSeriesToCircleList(double linqValue, string NameColumn, ref List<ISeries> ListOfPieSeries)
        {
            if (linqValue > 0)
            {
                PieSeries<double> OnePieSeries = this.GetOnePieSeries<double>(linqValue, NameColumn);
                ListOfPieSeries.Add(OnePieSeries);
            }

        }
        protected PieSeries<T> GetOnePieSeries<T>(T linqValue, string name)
        {
            PieSeries<T> pieSeries;

            pieSeries = new PieSeries<T>()
            {
                Name = name + ":" + linqValue.ToString(),
                Values = new T[] { linqValue },
                DataLabelsSize = 10.0,
                DataLabelsPadding = new Padding(0.0, 0.0, 0.0, 0.0),
                DataLabelsPosition = PolarLabelsPosition.End,
                DataLabelsMaxWidth = 20,
                Stroke = null,
                DataLabelsRotation = 0,
                DataLabelsPaint = new SolidColorPaint
                {
                    SKFontStyle = SKFontStyle.Bold,
                    Color = SKColors.Black,
                    SKTypeface = SKFontManager.Default.MatchCharacter('汉')
                },
                //显示在图上每块上面的数值
                //DataLabelsFormatter = (mypoint) =>
                //{
                //    //if (mypoint.PrimaryValue > 1.5)
                //    //{
                //    //    return $"{Row[NameColumn].ToString()}:{mypoint.PrimaryValue.ToString()}";
                //    //}
                //    //else
                //    //{
                //    //    return " ";
                //    //}
                //    if (mypoint.StackedValue.Share > 0.02)
                //    {
                //        return $"{name}:{mypoint.PrimaryValue.ToString()}";
                //    }
                //    else
                //    {
                //        return " ";
                //    }
                //},
                Pushout = 1,
                ToolTipLabelFormatter = point => string.Format("{0:P2}", point.StackedValue.Share),
            };

            return pieSeries;
        }
        private async void ShowSingleMsg()
        {
            if (SelectedCity.Value == null || SelectedCountry.Value == null || SelectedTown.Value == null)
            {
                await MyMessagebox.ShowAsyncInMainWindow("市、县、乡镇至少有一个下拉框未选择内容!", Icon.Error);

                return;
            }
            if (string.IsNullOrEmpty(SelectedIndicator.Value))
            {
                await MyMessagebox.ShowAsyncInMainWindow("未选择具体指标名称!", Icon.Warning);
                return;
            }
            DTForSingleIndicator = showMsg.GetSingleMsg(SelectedCity, SelectedCountry, SelectedTown, SelectedIndicator, withYSTableNameNow, withYSTableNamePre, withYSTableNameYOY);
            if (DTForSingleIndicator != null)
            {
                List<ISeries> CircleConsistOfPiecesOfIndicatorSeasonNowConvertToArrayFinally = new List<ISeries>();
                List<ISeries> CircleConsistOfPiecesOfIndicatorSeasonPreConvertToArrayFinally = new List<ISeries>();
                List<ISeries> CircleConsistOfPiecesOfIndicatorSeasonYOYConvertToArrayFinally = new List<ISeries>();
                List<double> ListColumnSeriesValuesIncreaseOfPreConvertToArryLast = new List<double>();
                List<double> ListColumnSeriesValuesIncreaseOfYOYConvertToArryLast = new List<double>();
                List<double> ListLineSeriesValuesIncreaseOfPreConvertToArrayLast = new List<double>();
                List<double> ListLineSeriesValuesIncreaseOfYOYConvertToArrayLast = new List<double>();
                List<string> ColumnsXAxisNames = new List<string>();
                List<string> ListLineXAxisNames = new List<string>();
                string NameInDT = null;
                string PieTitleName = null;
                if (SelectedCity.Value.Equals("全部"))
                {
                    NameInDT = "市";
                    PieTitleName = "分地市";
                }
                else if (SelectedCountry.Value.Equals("全部"))//全市的情况
                {
                    NameInDT = "县";
                    PieTitleName = "分县";
                }
                else if (SelectedCountry.Value.Equals("全部") == false && SelectedTown.Value.Equals("全部"))//某个县全县的情况
                {
                    NameInDT = "乡";
                    PieTitleName = "分乡镇";
                }
                else if (SelectedCountry.Value.Equals("全部") == false && SelectedTown.Value.Equals("全部") == false)//某个乡镇分户的情况
                {
                    NameInDT = "户主姓名";
                    PieTitleName = "分户";
                }
                for (int i = 0; i < DTForSingleIndicator.Rows.Count - 1; i++)
                {
                    DataRow Row = base.DTForSingleIndicator.Rows[i];
                    AddOnePieSeriesToCircleList(Row, NameInDT, $"本季度{SelectedIndicator.Value}", ref CircleConsistOfPiecesOfIndicatorSeasonNowConvertToArrayFinally);
                    AddOnePieSeriesToCircleList(Row, NameInDT, $"上季度{SelectedIndicator.Value}", ref CircleConsistOfPiecesOfIndicatorSeasonPreConvertToArrayFinally);
                    AddOnePieSeriesToCircleList(Row, NameInDT, $"同比季度{SelectedIndicator.Value}", ref CircleConsistOfPiecesOfIndicatorSeasonYOYConvertToArrayFinally);
                    AddTw0TotalColumsToCart(Row, 0, "环比增量", "同比增量", ref ListColumnSeriesValuesIncreaseOfPreConvertToArryLast, ref ListColumnSeriesValuesIncreaseOfYOYConvertToArryLast, ref ColumnsXAxisNames);
                    AddTw0TotalColumsToCart(Row, 0, "环比增幅(%)", "同比增幅(%)", ref ListLineSeriesValuesIncreaseOfPreConvertToArrayLast, ref ListLineSeriesValuesIncreaseOfYOYConvertToArrayLast, ref ListLineXAxisNames);
                }
                if (CircleConsistOfPiecesOfIndicatorSeasonNowConvertToArrayFinally.Count > 0)//如果当前季度的数据不为空,就显示到界面上
                {
                    PieSeriesOfNow = CircleConsistOfPiecesOfIndicatorSeasonNowConvertToArrayFinally.ToArray();
                    TitleOfPieSeriesNow = SetTitleOfPie($"规模户本季度{SelectedIndicator.Value}{PieTitleName}数据和比重示意图(%)");
                }
                else
                {
                    PieSeriesOfNow = null;
                    TitleOfPieSeriesNow = null;
                }
                if (CircleConsistOfPiecesOfIndicatorSeasonPreConvertToArrayFinally.Count > 0)//如果上季度的数据不为空,就显示到界面上
                {
                    PieSeriesOfPre = CircleConsistOfPiecesOfIndicatorSeasonPreConvertToArrayFinally.ToArray();
                    TitleOfPieSeriesPre = base.SetTitleOfPie("规模户上季度" + this.SelectedIndicator.Value + PieTitleName + "数据和比重示意图(%)");
                }
                else
                {
                    PieSeriesOfPre = null;
                    TitleOfPieSeriesPre = null;
                }
                if (CircleConsistOfPiecesOfIndicatorSeasonYOYConvertToArrayFinally.Count > 0)//如果同比季度的数据不为空,就显示到界面上
                {
                    PieSeriesOfYOY = CircleConsistOfPiecesOfIndicatorSeasonYOYConvertToArrayFinally.ToArray();
                    TitleOfPieSeriesYOY = SetTitleOfPie($"规模户同比季度{SelectedIndicator.Value}{PieTitleName}数据比重示意图(%)");
                }
                else
                {
                    PieSeriesOfYOY = null;
                    TitleOfPieSeriesYOY = null;
                }
                if (ListColumnSeriesValuesIncreaseOfPreConvertToArryLast.Count > 0)
                {
                    //直方图标题
                    TitleOfCartNow = GetTitleOfCart($"规模户{SelectedIndicator.Value}环比和同比增量数据");
                    CartSeriesNow = SetColumnsSeries<double, double>($"{SelectedIndicator.Value}环比增量", ListColumnSeriesValuesIncreaseOfPreConvertToArryLast,
                       $"{SelectedIndicator.Value}同比增量", ListColumnSeriesValuesIncreaseOfYOYConvertToArryLast);
                    CartXAxisOfNow = SetColumnsXAxis($"{PieTitleName}名称", ColumnsXAxisNames);
                    CartYAxisOfNow = SetColumnsYAxis(SelectedIndicator.Value + "增量数据");
                }
                else
                {
                    TitleOfCartNow = null;
                    CartXAxisOfNow = null;
                    CartYAxisOfNow = null;
                    CartSeriesNow = null;
                }
                if (ListLineSeriesValuesIncreaseOfPreConvertToArrayLast.Count > 0)
                {
                    LineTitle = base.SetTitleOfLine("规模户" + this.SelectedIndicator.Value + PieTitleName + "增幅图(%)");
                    LineSeries = base.SetLineSeries<double, double>(SelectedIndicator.Value + "环比增幅", ListLineSeriesValuesIncreaseOfPreConvertToArrayLast,
                        SelectedIndicator.Value + "同比增幅", ListLineSeriesValuesIncreaseOfYOYConvertToArrayLast);
                    LineXAxis = SetLineXAxis(PieTitleName + "名称", ListLineXAxisNames);
                    LineYAxis = SetLineYAxis(SelectedIndicator.Value + "增幅数据");
                }

                else
                {
                    LineTitle = null;
                    LineXAxis = null;
                    LineYAxis = null;
                    LineSeries = null;
                }




            }




        }

    }
}
